//
//  UtilsMacros.h
//  NiubilityProject
//
//  Created by Apple on 2017/11/16.
//  Copyright © 2017年 Apple. All rights reserved.
//

#ifndef UtilsMacros_h
#define UtilsMacros_h

//MARK:------------frame数值相关--------------
//根据文字内容和大小返回 size
CG_INLINE CGSize
JS_LabelSizeWithTextAndFont(NSString *text, UIFont *font){
    CGSize size = [text sizeWithAttributes:@{NSFontAttributeName:font}];
    CGSize newSize = CGSizeMake(size.width, size.height);
    return newSize;
}
//根据文字内容、宽度和字体返回 size
CG_INLINE CGSize
JS_LabelSizeWithTextAndWidthAndFont(NSString *text, CGFloat width, UIFont *font){
    CGSize size = CGSizeMake(width, MAXFLOAT);
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineBreakMode:NSLineBreakByCharWrapping];
    CGRect frame = [text boundingRectWithSize:size
                                      options:
                    NSStringDrawingTruncatesLastVisibleLine |
                    NSStringDrawingUsesLineFragmentOrigin |
                    NSStringDrawingUsesFontLeading
                                   attributes:@{NSFontAttributeName : font, NSParagraphStyleAttributeName : style} context:nil];
    CGRect newFrame = CGRectMake(frame.origin.x, frame.origin.y, width, frame.size.height);
    return newFrame.size;
}

CG_INLINE CGSize
JS_LabelSizeWithMutableAttributedStringAndWidthAndFont(NSMutableAttributedString *text, CGFloat width, UIFont *font){
    CGSize size = CGSizeMake(width, MAXFLOAT);
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineBreakMode:NSLineBreakByCharWrapping];
    
    //    if (![text isKindOfClass:[NSString class]] || ![text isKindOfClass:[NSAttributedString class]])
    //    {
    //        NSLog(@"text 错误，此功能仅限 NSString / NSAttributedString 类型！");
    //        return CGSizeZero;
    //    }
    CGRect frame = [[text copy] boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine |
                    NSStringDrawingUsesLineFragmentOrigin |
                    NSStringDrawingUsesFontLeading context:nil];
    CGRect newFrame = CGRectMake(frame.origin.x, frame.origin.y, width, frame.size.height);
    return newFrame.size;
}
/**
 *  基于指定的倍数，对传进来的 floatValue 进行像素取整。若指定倍数为0，则表示以当前设备的屏幕倍数为准。
 *
 *  例如传进来 “2.1”，在 2x 倍数下会返回 2.5（0.5pt 对应 1px），在 3x 倍数下会返回 2.333（0.333pt 对应 1px）。
 */
CG_INLINE float
flatfSpecificScale(float floatValue, float scale) {
    scale = scale == 0 ? ScreenScale : scale;
    CGFloat flattedValue = ceilf(floatValue * scale) / scale;
    return flattedValue;
}

/**
 *  基于当前设备的屏幕倍数，对传进来的 floatValue 进行像素取整。
 *
 *  注意如果在 Core Graphic 绘图里使用时，要注意当前画布的倍数是否和设备屏幕倍数一致，若不一致，不可使用 flatf() 函数。
 */
CG_INLINE float
flatf(float floatValue) {
    return flatfSpecificScale(floatValue, 0);
}

/**
 *  类似flatf()，只不过 flatf 是向上取整，而 floorfInPixel 是向下取整
 */
CG_INLINE float
floorfInPixel(float floatValue) {
    CGFloat resultValue = floorf(floatValue * ScreenScale) / ScreenScale;
    return resultValue;
}

CG_INLINE BOOL
betweenf(float minimumValue, float value, float maximumValue) {
    return minimumValue < value && value < maximumValue;
}

CG_INLINE BOOL
betweenOrEqualf(float minimumValue, float value, float maximumValue) {
    return minimumValue <= value && value <= maximumValue;
}

/**
 *  国际化默认语言设置
 *  如果当前语言环境不是中文 默认显示英文环境
 */
#define CURR_LANG   ([[NSLocale preferredLanguages] objectAtIndex:0])
CG_INLINE NSString *
JSLocalizedString(NSString * translation_key) {
    NSString * LocalizableStr = NSLocalizedString(translation_key, nil);
    if (!([CURR_LANG rangeOfString:@"zh-Hant"].length >0) &&
        !([CURR_LANG rangeOfString:@"zh-Hans"].length >0)) {
        
        NSString * path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
        
        NSBundle * languageBundle = [NSBundle bundleWithPath:path];
        
        LocalizableStr = [languageBundle localizedStringForKey:translation_key value:@"" table:nil];
    }
    return LocalizableStr;
}
/**
 * 判断是非是中文环境
 */
CG_INLINE BOOL
JSLocalizeIsChina(){
    return [CURR_LANG rangeOfString:@"zh-Hant"].length >0 || [CURR_LANG rangeOfString:@"zh-Hans"].length > 0;
}

//MARK:国际化语言key
static  NSString *kLocalizableAlertTitle = @"alertTitle";
static  NSString *kLocalizableAlertOk    = @"alertOk";
static  NSString *kLocalizableAlertOthe  = @"alertOther";
static  NSString *kLocalizableRegister   = @"register";
static  NSString *kLocalizableLogin      = @"login";
static  NSString *kLocalizableLoginOut   = @"loginOut";
static  NSString *kLocalizablePassWord   = @"passWord";
static  NSString *kLocalizableUsername   = @"username";
static  NSString *kLocalizableCancel     = @"cancel";
static  NSString *kLocalizableYes        = @"yes";
static  NSString *kLocalizableOk         = @"ok";
static  NSString *kLocalizableNo         = @"no";
static  NSString *kLocalizableSearch     = @"search";
static  NSString *kLocalizableLoading    = @"loading";
static  NSString *kLocalizableNetworkError    = @"networkerror";
static  NSString *kLocalizableNext       = @"nextLoca";
static  NSString *kLocalizableFinish     = @"finishLoca";
static  NSString *kLocalizableServerError     = @"serverErrorLoca";
static  NSString *kLocalizableSearchResult     = @"serachresult";
static NSString *kLocalizableSuccess     = @"success";
static NSString *kLocalizableSeeting     = @"seetingLoca";


#pragma mark - ——————— 常用正则 ————————
/*!
 *  检测是否为邮箱
 *
 *  @param emailStr 传入需要检测的字符串
 *
 *  @return 返回检测结果 是或者不是
 */
CG_INLINE BOOL
JSRegularIsEmailQualified(NSString * emailStr) {
    NSString *pattern = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:pattern options:0 error:nil];
    NSArray *results = [regex matchesInString:emailStr options:0 range:NSMakeRange(0, emailStr.length)];
    return results.count > 0;
}
/*!
 *  检测用户输入密码是否以字母开头，长度在6-18之间，只能包含字符、数字和下划线。
 *
 *  @param passwordStr 传入需要检测的字符串
 *
 *  @return 返回检测结果 是或者不是
 */
CG_INLINE BOOL
JSRegularIsPasswordQualified(NSString *passwordStr){
    
    NSString *passWordRegex = @"^[a-zA-Z]\\w.{5,17}$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:passwordStr];
}
/*!
 *  验证身份证号（15位或18位数字）【最全的身份证校验，带校验位】
 *  @param idCardNumberStr 传入需要检测的字符串
 *
 *  @return 返回检测结果 是或者不是
 */
CG_INLINE BOOL
JSRegularIsIdCardNumberQualified(NSString *idCardNumberStr){
    idCardNumberStr = [idCardNumberStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSInteger length = 0;
    if (!idCardNumberStr)
    {
        return NO;
    }
    else
    {
        length = idCardNumberStr.length;
        if (length != 15 && length !=18)
        {
            return NO;
        }
    }
    /*! 省份代码 */
    NSArray *areasArray =@[@"11", @"12", @"13", @"14", @"15", @"21", @"22", @"23", @"31", @"32", @"33", @"34", @"35", @"36", @"37", @"41", @"42", @"43", @"44", @"45", @"46", @"50", @"51", @"52", @"53", @"54", @"61", @"62", @"63", @"64", @"65", @"71", @"81", @"82", @"91"];
    
    NSString *valueStart2 = [idCardNumberStr substringToIndex:2];
    BOOL areaFlag = NO;
    for (NSString *areaCode in areasArray)
    {
        if ([areaCode isEqualToString:valueStart2])
        {
            areaFlag =YES;
            break;
        }
    }
    if (!areaFlag)
    {
        return NO;
    }
    
    NSRegularExpression *regularExpression;
    NSUInteger numberofMatch;
    
    NSInteger year = 0;
    switch (length)
    {
        case 15:
            year = [idCardNumberStr substringWithRange:NSMakeRange(6,2)].intValue +1900;
            
            if (year % 4 ==0 || (year % 100 ==0 && year % 4 ==0))
            {
                /*! 测试出生日期的合法性 */
                regularExpression = [[NSRegularExpression alloc] initWithPattern:@"^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$"
                                                                         options:NSRegularExpressionCaseInsensitive
                                                                           error:nil];
            }
            else
            {
                /*! 测试出生日期的合法性 */
                regularExpression = [[NSRegularExpression alloc] initWithPattern:@"^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$"
                                                                         options:NSRegularExpressionCaseInsensitive
                                                                           error:nil];
            }
            numberofMatch = [regularExpression numberOfMatchesInString:idCardNumberStr
                                                               options:NSMatchingReportProgress
                                                                 range:NSMakeRange(0, idCardNumberStr.length)];
            
            if(numberofMatch > 0)
            {
                return YES;
            }
            else
            {
                return NO;
            }
            break;
        case 18:
            
            year = [idCardNumberStr substringWithRange:NSMakeRange(6,4)].intValue;
            if (year % 4 ==0 || (year % 100 ==0 && year % 4 ==0))
            {
                /*! 测试出生日期的合法性 */
                regularExpression = [[NSRegularExpression alloc] initWithPattern:@"^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$"
                                                                         options:NSRegularExpressionCaseInsensitive
                                                                           error:nil];
            }
            else
            {
                /*! 测试出生日期的合法性 */
                regularExpression = [[NSRegularExpression alloc] initWithPattern:@"^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$"
                                                                         options:NSRegularExpressionCaseInsensitive
                                                                           error:nil];
            }
            numberofMatch = [regularExpression numberOfMatchesInString:idCardNumberStr
                                                               options:NSMatchingReportProgress
                                                                 range:NSMakeRange(0, idCardNumberStr.length)];
            
            if(numberofMatch > 0)
            {
                NSInteger S = ([idCardNumberStr substringWithRange:NSMakeRange(0,1)].intValue + [idCardNumberStr substringWithRange:NSMakeRange(10,1)].intValue) *7 + ([idCardNumberStr substringWithRange:NSMakeRange(1,1)].intValue + [idCardNumberStr substringWithRange:NSMakeRange(11,1)].intValue) *9 + ([idCardNumberStr substringWithRange:NSMakeRange(2,1)].intValue + [idCardNumberStr substringWithRange:NSMakeRange(12,1)].intValue) *10 + ([idCardNumberStr substringWithRange:NSMakeRange(3,1)].intValue + [idCardNumberStr substringWithRange:NSMakeRange(13,1)].intValue) *5 + ([idCardNumberStr substringWithRange:NSMakeRange(4,1)].intValue + [idCardNumberStr substringWithRange:NSMakeRange(14,1)].intValue) *8 + ([idCardNumberStr substringWithRange:NSMakeRange(5,1)].intValue + [idCardNumberStr substringWithRange:NSMakeRange(15,1)].intValue) *4 + ([idCardNumberStr substringWithRange:NSMakeRange(6,1)].intValue + [idCardNumberStr substringWithRange:NSMakeRange(16,1)].intValue) *2 + [idCardNumberStr substringWithRange:NSMakeRange(7,1)].intValue *1 + [idCardNumberStr substringWithRange:NSMakeRange(8,1)].intValue *6 + [idCardNumberStr substringWithRange:NSMakeRange(9,1)].intValue *3;
                NSInteger Y = S % 11;
                NSString *M = @"F";
                NSString *JYM = @"10X98765432";
                /*! 判断校验位 */
                M = [JYM substringWithRange:NSMakeRange(Y,1)];
                if ([M isEqualToString:[idCardNumberStr substringWithRange:NSMakeRange(17,1)]])
                {
                    /*! 检测ID的校验位 */
                    return YES;
                }
                else
                {
                    return NO;
                }
                
            }
            else
            {
                return NO;
            }
            break;
        default:
            return NO;
            break;
    }
}
CG_INLINE BOOL
JSRegularIsUrl(NSString *urlStr){
    if (!urlStr.length) {
        return NO;
    }
    NSString *pattern = @"\\b(([\\w-]+://?|www[.])[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|/)))";
    NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:pattern options:0 error:nil];
    NSArray *results = [regex matchesInString:urlStr options:0 range:NSMakeRange(0, urlStr.length)];
    return results.count > 0;
}
CG_INLINE BOOL
JSRegularIsPhone(NSString *mobileNum){
    NSString * MOBILE = @"^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$";
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    return [regextestmobile evaluateWithObject:mobileNum];
}
CG_INLINE void
JSSetingLableInfo(UIView *lable, CGFloat fontSize, UIColor *textColor){
    if ([lable isKindOfClass:[YYLabel class]]) {
        YYLabel *obj = (YYLabel *)lable;
        obj.textColor = textColor;
        obj.font = UIFontMake(fontSize);
    }else if ([lable isKindOfClass:[UILabel class]]){
        UILabel *obj = (UILabel *)lable;
        obj.textColor = textColor;
        obj.font = UIFontMake(fontSize);
    }
}

#pragma mark - ——————— 用户相关 ————————
//登录状态改变通知
#define KNotificationLoginStateChange @"loginStateChange"
//自动登录成功
#define KNotificationAutoLoginSuccess @"KNotificationAutoLoginSuccess"
//被踢下线
#define KNotificationOnKick @"KNotificationOnKick"

#pragma mark - ——————— color相关 ————————

CG_INLINE UIColor *
JS_colorWithHexA(NSInteger hexValue, CGFloat alphaValue){
    return [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0
                           green:((float)((hexValue & 0xFF00) >> 8))/255.0
                            blue:((float)(hexValue & 0xFF))/255.0 alpha:alphaValue];
}

CG_INLINE UIColor *
JS_colorWithHex(NSInteger hexValue){
    return JS_colorWithHexA(hexValue, 1);
}
/*! App 主题色 */
static NSInteger const kBodyColor = 0xEC647D;
/*! App 背景色 */
static NSInteger const kBodyBGColor = 0xF9F9F9;
/*! App 线 */
static NSInteger const kBodyLineColor = 0xc9c9c9;
/*! 导航栏文字颜色 */
static NSInteger const kNavBarTitleColor = 0xffffff;
static NSInteger const kNavBarTintColor  = 0xffffff;
/*! 导航栏文字颜色 */
static NSInteger const kTabBarTitleColor  = 0x000000;
static NSInteger const kTabBarSeletColor  = kBodyColor;

//static NSInteger const kClearColor  = 0xff;

/*! 黑色 */
static NSInteger const kBodyBlack   = 0x1b1a20;
static NSInteger const kColorBlack1 = 0x111111;
static NSInteger const kColorBlack2 = 0x222222;
static NSInteger const kColorBlack3 = 0x333333;
static NSInteger const kColorBlack4 = 0x444444;
static NSInteger const kColorBlack5 = 0x555555;

/*! 灰色 */
static NSInteger const kColorGray1 = 0x666666;
static NSInteger const kColorGray2 = 0x777777;
static NSInteger const kColorGray3 = 0x888888;
static NSInteger const kColorGray4 = 0x999999;
static NSInteger const kColorGray5 = 0xaaaaaa;
static NSInteger const kColorGray6 = 0xbbbbbb;


static NSInteger const kColor102 = kColorGray1; // 0x666666
static NSInteger const kColor68 = kColorBlack4; // 0x444444
static NSInteger const kColor34 = kColorBlack2; // 0x222222
static NSInteger const kColorShadow = 0xbebebe; // 0.35
static NSInteger const kColor194 = 0xC2C2C2; //
static NSInteger const kColor_47_155_239 = 0x2F9BEF;
static NSInteger const kColor_253_17_66 = 0xFD1142;
static NSInteger const kColor153 = kColorGray4; // 0x999999

#pragma mark ------ frmae ---------
static NSInteger const kBodyBtnHeight = 48;
static NSInteger const kBodyFontSize  = 16;
static NSInteger const kBodyMargin_10  = 10;


// 提示框
NS_INLINE void JSAlertWithMessge(NSString *messge){
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"提示" message:messge delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [alerView show];
        [alerView performSelector:@selector(dismissWithClickedButtonIndex:animated:) withObject:@[@0, @1] afterDelay:0.9];
    });
}
NS_INLINE void configLabel(UIView *lable, NSInteger fontSize, UIColor *textColor, NSString *content){
    if ([lable isKindOfClass:[UILabel class]]) {
        UILabel *temp = (UILabel *)lable;
        temp.font = UIFontMake(fontSize);
        temp.textColor = textColor;
        if (content) {
            temp.text = content;
        }
    }else if ([lable isKindOfClass:[YYLabel class]]){
        YYLabel *temp = (YYLabel *)lable;
        temp.font = UIFontMake(fontSize);
        temp.textColor = textColor;
        if (content) {
            temp.text = content;
        }
    }
}
NS_INLINE void configTextField(UIView *textField, NSInteger fontSize, UIColor *textColor, NSString *placeholder){
    if ([textField isKindOfClass:[UITextField class]]) {
        UITextField *temp = (UITextField *)textField;
        temp.font = UIFontMake(fontSize);
        temp.textColor = textColor;
        temp.placeholder = placeholder;
    }else if ([textField isKindOfClass:[QMUITextField class]]){
        QMUITextField *temp = (QMUITextField *)textField;
        temp.font = UIFontMake(fontSize);
        temp.textColor = textColor;
        temp.placeholder = placeholder;
        
    }
}
NS_INLINE void configBtn(UIView *btn, NSInteger fontSize, UIColor *textColor, NSString *curTitle){
    if ([btn isKindOfClass:[UIButton class]]) {
        UIButton *temp = (UIButton *)btn;
        temp.titleLabel.font = UIFontMake(fontSize);
        [temp setTitleColor:textColor forState:UIControlStateNormal];
        [temp setTitle:curTitle forState:UIControlStateNormal];
    }else if ([btn isKindOfClass:[QMUIButton class]]){
        QMUIButton *temp = (QMUIButton *)btn;
        temp.titleLabel.font = UIFontMake(fontSize);
        [temp setTitleColor:textColor forState:UIControlStateNormal];
        [temp setTitle:curTitle forState:UIControlStateNormal];
        
    }
}
/*! 用safari打开URL */
#define JS_OpenUrl(urlStr)      [JS_SharedApplication openURL:[NSURL URLWithString:urlStr]]
/*! APP版本号 */
#define JS_AppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define BASE_URL @"http://azbsj.yq008.com"
#define JS_VC_PUSHVC_ANIMATION(animation) [self.navigationController pushViewController:vc animated:animation]
//获取系统对象
#define kApplication        [UIApplication sharedApplication]
#define kAppWindow          [UIApplication sharedApplication].delegate.window
#define kAppDelegate        [AppDelegate shareAppDelegate]
#define kRootViewController [UIApplication sharedApplication].delegate.window.rootViewController
#define kUserDefaults       [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]

#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight 44.0
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
#define kTopHeight (kStatusBarHeight + kNavBarHeight)
#define kTopSpace KScreenHeight >= 812?20:0
//获取屏幕宽高
#define KScreenWidth ([[UIScreen mainScreen] bounds].size.width)
#define KScreenHeight [[UIScreen mainScreen] bounds].size.height
#define kScreen_Bounds [UIScreen mainScreen].bounds
#define Iphone6ScaleWidth KScreenWidth/375.0
#define Iphone6ScaleHeight KScreenHeight/667.0
//根据ip6的屏幕来拉伸
#define kRealValue(with) ((with)*(KScreenWidth/375.0f))

//强弱引用
#define kWeakSelf(type)  __weak typeof(type) weak##type = type;
#define kStrongSelf(type) __strong typeof(type) type = weak##type;

//View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

//-------------------打印日志-------------------------
//DEBUG  模式下打印日志,当前行
#ifdef DEBUG
#define JSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define JSLog(...)
#endif

//拼接字符串
#define NSStringFormat(format,...) [NSString stringWithFormat:format,##__VA_ARGS__]

//数据验证
#define StrValid(f) (f!=nil && [f isKindOfClass:[NSString class]] && ![f isEqualToString:@""])
#define SafeStr(f) (StrValid(f) ? f:@"")
#define HasString(str,key) ([str rangeOfString:key].location!=NSNotFound)

#define ValidStr(f) StrValid(f)
#define ValidDict(f) (f!=nil && [f isKindOfClass:[NSDictionary class]])
#define ValidArray(f) (f!=nil && [f isKindOfClass:[NSArray class]] && [f count]>0)
#define ValidNum(f) (f!=nil && [f isKindOfClass:[NSNumber class]])
#define ValidClass(f,cls) (f!=nil && [f isKindOfClass:[cls class]])
#define ValidData(f) (f!=nil && [f isKindOfClass:[NSData class]])

//发送通知
#define KPostNotification(name,obj) [[NSNotificationCenter defaultCenter] postNotificationName:name object:obj];

//单例化一个类
#define SINGLETON_FOR_HEADER(className) \
\
+ (className *)shared##className;

#define SINGLETON_FOR_CLASS(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}
#define defauldUserIcon UIImageMake(@"defaultUserImage")
#endif /* UtilsMacros_h */

